<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*, kr.cadis.clms.dao.*, kr.cadis.clms.model.*, java.sql.Date, kr.cadis.clms.util.Util" %>    
<%
	HolydayDao holydayDao = new HolydayDao();
	List<Holyday> holydayes = holydayDao.selectAll();
	Calendar calendar = Calendar.getInstance();
	int holydaylength = 0;
	
	// 오늘이 이번 주의 몇번째 날인가? 요일은 숫자로 가져옴
	int intDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

	String dayOfWeek = Util.makeDayOfWeekToKorean(intDayOfWeek);
	
	// 오늘은 스트링으로 만듬 ('yyyy-mm-dd')
	String strTheDate = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DATE);
	
	Calendar calendarMondayForThisWeek = Calendar.getInstance();

	// 이번 주의 월요일 찾기	
	calendarMondayForThisWeek.add(Calendar.DAY_OF_WEEK, 2 - intDayOfWeek);
	
	String strMondayOfThisWeek = calendarMondayForThisWeek.get(Calendar.YEAR) + "-" + (calendarMondayForThisWeek.get(Calendar.MONTH) + 1) + "-" + calendarMondayForThisWeek.get(Calendar.DATE);
	String strSundayOfThisWeek = calendarMondayForThisWeek.get(Calendar.YEAR) + "-" + (calendarMondayForThisWeek.get(Calendar.MONTH) + 1) + "-" + (calendarMondayForThisWeek.get(Calendar.DATE)-1);
	
	Date SundayOfThisWeek = Date.valueOf(strSundayOfThisWeek);

	for(int i = 0; i < 5; i++) {
		calendarMondayForThisWeek.add(Calendar.DAY_OF_WEEK, 1);
	}
	
	String strFridayOfThisWeek = calendarMondayForThisWeek.get(Calendar.YEAR) + "-" + (calendarMondayForThisWeek.get(Calendar.MONTH) + 1) + "-" + (calendarMondayForThisWeek.get(Calendar.DATE)-1);
	String strSaturdayOfThisWeek = calendarMondayForThisWeek.get(Calendar.YEAR) + "-" + (calendarMondayForThisWeek.get(Calendar.MONTH) + 1) + "-" + calendarMondayForThisWeek.get(Calendar.DATE);
	
	Date SatudayOfThisWeek = Date.valueOf(strSaturdayOfThisWeek);
	
	/* for(Holyday holyday : holydayes) {
		if(holyday.getThisDay().after(SundayOfThisWeek) && holyday.getThisDay().before(SatudayOfThisWeek)) {
			holydaylength += 1;
		}
	} */
	
	holydaylength = holydayDao.selectHolydayCountByThisWeek(strMondayOfThisWeek, strFridayOfThisWeek);
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<br><br>
<table border="1">

	<tr>
		<th>이번주</th>
		<th>오늘 날짜</th>
		<th>총 휴일수</th>
		<th>출근 일수</th>
	</tr>
	<tr>
		<th><%=strSundayOfThisWeek + " ~  <br> " + strSaturdayOfThisWeek  %> </th>
		<th><%= strTheDate + " " + dayOfWeek%>요일</th>
		<th> <%= holydaylength %> </th>
		<th> <%= 5 - holydaylength %> </th>
	</tr>
</table><br><br>
<h1>금주 휴일 현황</h1>
<table border="1">
	<tr><th>날짜</th><th>사유</th><th>수정</th><th>삭제</th></tr>
<%
	for(Holyday holyday : holydayes) {
		if(holyday.getThisDay().after(SundayOfThisWeek) && holyday.getThisDay().before(SatudayOfThisWeek)) {
%>	
	<tr>
		<td><%= holyday.getThisDay() %></td>
		<td style="text-align: right;"><%= holyday.getWhatDay() %></td>
		<td><a href="Update.jsp?thisDay=<%= holyday.getThisDay() %>">수정</a></td>
		<td><a href="Delete.jsp?thisDay=<%= holyday.getThisDay() %>">삭제</a></td>
	</tr>
<%
		}
	}
%>	
</table>
<br />
<a href="Insert.jsp">신규 설정</a>
<br />
<a href="ListAll.jsp">전체 휴일 보기</a><br />
<a href="/CLMSWeb/index.jsp">처음화면으로 돌아가기</a>
</body>
</html>